package com.wxj.book.controller;

import com.github.pagehelper.PageInfo;
import com.wxj.book.pojo.Book;
import com.wxj.book.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class SearchController {
    @Autowired
    private BookService bookService;

    /**
     * 模糊查询
     */
    @RequestMapping("search/book")
    public String searchBook(@RequestParam("key") String key,
                             Model model,
                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize) {
        PageInfo<Book> pageInfo = bookService.getByKey(pageNum, pageSize, key);
        model.addAttribute("pageInfo", pageInfo);
        return "searchList";
    }
}
